package org.xbill.DNS;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.xbill.DNS.utils.base16;

public class NSAPRecord extends Record
{
  private static final long serialVersionUID = 225215775L;
  private byte[] address;

  public NSAPRecord(Name paramName, int paramInt, long paramLong, String paramString)
  {
    super(paramName, 22, paramInt, paramLong);
    this.address = checkAndConvertAddress(paramString);
    if (this.address == null)
      throw new IllegalArgumentException("invalid NSAP address " + paramString);
  }

  private static final byte[] checkAndConvertAddress(String paramString)
  {
    byte[] arrayOfByte;
    if (!(paramString.substring(0, 2).equalsIgnoreCase("0x")))
      arrayOfByte = null;
    while (true)
    {
      ByteArrayOutputStream localByteArrayOutputStream;
      int i;
      int j;
      int k;
      while (true)
      {
        return arrayOfByte;
        localByteArrayOutputStream = new ByteArrayOutputStream();
        i = 0;
        j = 0;
        k = 2;
        if (k < paramString.length())
          break;
        if (i == 0)
          break label126;
        arrayOfByte = null;
      }
      char c = paramString.charAt(k);
      if (c == '.');
      while (true)
      {
        int l;
        while (true)
        {
          while (true)
          {
            while (true)
              ++k;
            l = Character.digit(c, 16);
            if (l != -1)
              break;
            arrayOfByte = null;
          }
          if (i == 0)
            break;
          j += l;
          localByteArrayOutputStream.write(j);
          i = 0;
        }
        j = l << 4;
        i = 1;
      }
      label126: arrayOfByte = localByteArrayOutputStream.toByteArray();
    }
  }

  public String getAddress()
  {
    return byteArrayToString(this.address, false);
  }

  Record getObject()
  {
    return new NSAPRecord();
  }

  void rdataFromString(Tokenizer paramTokenizer, Name paramName)
    throws IOException
  {
    String str = paramTokenizer.getString();
    this.address = checkAndConvertAddress(str);
    if (this.address == null)
      throw paramTokenizer.exception("invalid NSAP address " + str);
  }

  void rrFromWire(DNSInput paramDNSInput)
    throws IOException
  {
    this.address = paramDNSInput.readByteArray();
  }

  String rrToString()
  {
    return "0x" + base16.toString(this.address);
  }

  void rrToWire(DNSOutput paramDNSOutput, Compression paramCompression, boolean paramBoolean)
  {
    paramDNSOutput.writeByteArray(this.address);
  }
}